const express = require('express');
const router = express.Router();
const { success, failure } = require('../../utils/responses')
const { initOrderStream, broadcastOrderCount, countOrder } = require('../../streams/count-order');
/**
 * SSE 统计每个月订单数量
 * GET /admin/charts/stream_order
 */
router.get('/stream_order', async (req, res) => {
    try {
        initOrderStream(res, req);
        // await broadcastOrderCount();
    } catch (error) {
        failure({ res, error });
    }
});

/**
 * 统计初始订单数量
 * GET /admin/charts/order
 */
router.get('/order', async (req, res) => {
    try {
        const data = await countOrder()
        success({ data, res })
    } catch (error) {
        failure({ res, error });
    }
});


module.exports = router;